﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Common;

namespace RegisterationSystem.Space_School
{
    public partial class notice_management : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                switch (Request.Form["action"])
                {
                    case "updstatus":
                        UpdNoticeStatus();
                        break;
                    case "del":
                        DelNotice();
                        break;
                    case "updnotice":
                        UpdNotice();
                        break;

                }
            }
        }

        //修改公告信息
        void UpdNotice()
        {
            string id = Request.Form["id"];
            string status = Request.Form["status"];
            string tile = Request.Form["tile"];
            string count = Request.Form["count"];
            string rec = Request.Form["rec"];
            RParams param = new RParams();
            param.Add("Status",Convert.ToInt32(status));
            param.Add("Title",tile);
            param.Add("Content",count);
            param.Add("Recrive", rec);
            DBAction.Update("NoticeParents", "Title,Content,Status,Recrive", "ID=" + id, param);
        }
        //删除
        void DelNotice()
        {
            string id = Request.Form["id"];
            id = id.Substring(0, id.Length - 1);
            string[] ids = id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < ids.Length; i++)
            {
                if (!string.IsNullOrEmpty(ids[i].ToString().Trim()))
                {
                    DBAction.Delete("NoticeParents","ID=" + ids[i]);
                    //将公告删除的同时，也将数据库中的公告阅读人的信息删除
                    DBAction.Delete("NoticeReceive", "NoticeID=" + ids[i]);
                }
            }
        }
        //批量修改公告接受对象
        void UpdNoticeList()
        {
            string idlist = Request.Form["id"];
            string countlist = Request.Form["count"];
            string[] ids = idlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string[] counts = countlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        }
        //批量修改状态
        void UpdNoticeStatus()
        {
            string idlist = Request.Form["id"];
            string sid = Request.Form["sid"];
            string[] ids = idlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            RParams param = new RParams ();
            param.Add("Status",Convert.ToInt32(sid));
            for (int i = 0; i < ids.Length; i++)
            {
                if (!string.IsNullOrEmpty(ids[i].ToString().Trim()))
                {
                    DBAction.Update("NoticeParents", "Status", "ID=" + ids[i], param);
                }
            }
        }
    }
}